module dgl.graphics.ShaderUniformCollection;

import tango.stdc.stringz;
import tango.io.Console;
import Integer = tango.text.convert.Integer;

import derelict.opengl.gl;

import dgl.Vector2;
import dgl.Vector3;
import dgl.Vector4;
import dgl.Matrix;

import dgl.graphics.ShaderParameterCollection;
import dgl.graphics.ShaderProgram;
import dgl.graphics.Texture2D;

class ShaderUniformCollection : ShaderParameterCollection
{	
	public this( ShaderProgram program )
	{
		super( program );
	}
	
	public void opIndexAssign( int value, char[] parameterName )
	{
		auto location = glGetUniformLocation( m_program.id, toStringz( parameterName ) );
		glUniform1i( location, value );
	}
	
	public void opIndexAssign( float value, char[] parameterName )
	{
		auto location = glGetUniformLocation( m_program.id, toStringz( parameterName ) );
		glUniform1f( location, value );
	}
	
	public void opIndexAssign( Vector2 value, char[] parameterName )
	{
		auto location = glGetUniformLocation( m_program.id, toStringz( parameterName ) );
		glUniform2fv( location, 1, value.ptr );
	}
	
	public void opIndexAssign( Vector3 value, char[] parameterName )
	{
		auto location = glGetUniformLocation( m_program.id, toStringz( parameterName ) );
		glUniform3fv( location, 1, value.ptr );
	}
	
	public void opIndexAssign( Vector4 value, char[] parameterName )
	{
		auto location = glGetUniformLocation( m_program.id, toStringz( parameterName ) );
		glUniform4fv( location, 1, value.ptr );
	}
	
	public void opIndexAssign( Matrix value, char[] parameterName )
	{
		auto location = glGetUniformLocation( m_program.id, toStringz( parameterName ) );
		glUniformMatrix4fv( location, 1, 0, value.ptr );
	}
	
	public void opIndexAssign( Texture2D value, char[] parameterName )
	{
		glActiveTexture( GL_TEXTURE0 );
		glBindTexture( GL_TEXTURE_2D, value.id );
		auto location = glGetUniformLocation( m_program.id, toStringz( parameterName ) );
		glUniform1i( location, 0 );
	}
}